<script lang="ts">
export default {
  name: "deviceWarnLog",
};
</script>

<script setup lang="ts">
import {
	DeviceListVO,
} from "@/api/device/logtypes";
import { DeviceWarnLogPageResult, DeviceWarnLogQuery, DeviceWarnLogPageVO } from "@/api/device/warnLogTypes";
import { getDeviceList } from "@/api/device/log";
import { getDeviceWarnLogPage } from "@/api/device/warnLog";

const queryFormRef = ref(ElForm);
const deviceList = ref<DeviceListVO[]>();

const loading = ref(false);
const total = ref(0);

const queryParams = reactive<DeviceWarnLogQuery>({
  pageNum: 1,
  pageSize: 10,
});

const dataList = ref<DeviceWarnLogPageVO[]>();

/**
 * 查询设备
 */
function getDevice() {
	loading.value = true;
	getDeviceList()
		.then(({ data }) => {
			deviceList.value = data;
		})
		.finally(() => {
			loading.value = false;
		});
}

/**
 * 查询设备实时数据
 */
function handleQuery() {
  loading.value = true;
  getDeviceWarnLogPage(queryParams)
    .then(({ data }) => {
			dataList.value = data.list;
      total.value = data.total;
    })
    .finally(() => {
      loading.value = false;
    });
}

/**
 * 重置查询
 */
function resetQuery() {
  queryFormRef.value.resetFields();
  queryParams.pageNum = 1;
  handleQuery();
}

onMounted(() => {
  handleQuery();
	getDevice();
});
</script>

<template>
  <div class="app-container">
    <div class="search">
      <el-form ref="queryFormRef" :model="queryParams" :inline="true">
				<el-form-item label="设备名称：">
					<el-select
						v-model="queryParams.deviceId"
						placeholder="请选择设备名称"
						prop="deviceId"
					>
						<el-option
							v-for="item in deviceList"
							:key="item.id"
							:label="item.name"
							:value="item.id"
						>
						</el-option>
					</el-select>
				</el-form-item>
        <el-form-item label="数据类型：">
          <el-select
            v-model="queryParams.dataType"
            placeholder="请选择数据类型"
            prop="dataType"
          >
            <el-option label="pm" value="PM">pm</el-option>
            <el-option label="液位" value="YW">液位</el-option>
            <el-option label="温度" value="TEMP">温度</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="日期：">
          <el-date-picker
            v-model="queryParams.startTime"
            type="datetime"
            placeholder="选择开始时间"
          >
          </el-date-picker>
          <span>-</span>
          <el-date-picker
            v-model="queryParams.endTime"
            type="datetime"
            placeholder="选择结束时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery">
            <i-ep-search />
            搜索
          </el-button>
          <el-button @click="resetQuery">
            <i-ep-refresh />
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never">
      <template #header> </template>

      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="dataList"
        highlight-current-row
        border
      >
        <el-table-column label="设备名称" prop="deviceName" />
        <el-table-column label="告警类型" prop="type" />
        <el-table-column label="处理状态" prop="status" />
				<el-table-column label="配置值" prop="configValue">
				</el-table-column>
				<el-table-column label="触发值" prop="realValue" />
        <el-table-column label="上报时间" prop="time" />
      </el-table>

      <pagination
        v-if="total > 0"
        v-model:total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="handleQuery"
      />
    </el-card>
  </div>
</template>
